﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Common.Library;
using System.ComponentModel;
using OnlineVideos.Data;
using OnlineVideos.Common;
using System.Windows.Navigation;
using Common;
using Common.Utilities;
using OnlineVideos.Entities;


namespace OnlineVideos
{
    public partial class CricketSummary : UserControl
    {
        List<MatchBowlingScore> objbowlingsummary = null;
        List<MatchBattingScore> objbattingsummary = null;
        MatchExtras objextras = null;
        public CricketSummary()
        {
            InitializeComponent();
            MyProgressBar1.IsIndeterminate = true;
            objbowlingsummary = new List<MatchBowlingScore>();
            objbattingsummary = new List<MatchBattingScore>();
            objextras = new MatchExtras();
            Loaded += new RoutedEventHandler(CricketSummary_Loaded);
        }

        void CricketSummary_Loaded(object sender, RoutedEventArgs e)
        {

            try
            {
                GetPageDataInBackground();

                CricketMatch.GetCricketTeam1Title(AppSettings.ShowID);
            }
            catch (Exception ex)
            {
                
                Exceptions.SaveOrSendExceptions("Exception in CricketSummary_Loaded Method In CricketSummary.cs file.", ex);
            }
        }
        private void GetPageDataInBackground()
        {
            BackgroundHelper bwHelper = new BackgroundHelper();

            bwHelper.AddBackgroundTask(
                                        (object s, DoWorkEventArgs a) =>
                                        {

                                            a.Result = CricketMatch.LoadBattingSummary(AppSettings.ShowID, TeamType.TeamABatting);
                                        },
                                        (object s, RunWorkerCompletedEventArgs a) =>
                                        {

                                            objbattingsummary = (List<MatchBattingScore>)a.Result;
                                            if (objbattingsummary.Count > 0)
                                            {
                                                lbxteamAsummary.ItemsSource = objbattingsummary;
                                               

                                            }
                                            else
                                            {
                                               
                                            }

                                        }
                                      );
            bwHelper.AddBackgroundTask(
                                      (object s, DoWorkEventArgs a) =>
                                      {

                                          a.Result = CricketMatch.LoadBattingSummary(AppSettings.ShowID, TeamType.TeamBBatting);
                                      },
                                      (object s, RunWorkerCompletedEventArgs a) =>
                                      {

                                          objbattingsummary = (List<MatchBattingScore>)a.Result;
                                          if (objbattingsummary.Count > 0)
                                          {
                                              lbxteamBsummary.ItemsSource = objbattingsummary;
                                              

                                          }
                                          else
                                          {
                                              
                                          }

                                      }
                                    );
            bwHelper.AddBackgroundTask(
                                       (object s, DoWorkEventArgs a) =>
                                       {

                                           a.Result = CricketMatch.LoadbowlingSummary(AppSettings.ShowID, TeamType.TeamABowling);
                                       },
                                       (object s, RunWorkerCompletedEventArgs a) =>
                                       {

                                           objbowlingsummary = (List<MatchBowlingScore>)a.Result;
                                           if (objbowlingsummary.Count > 0)
                                           {
                                               lbxteamAsummarybowling.ItemsSource = objbowlingsummary;
                                              

                                           }
                                           else
                                           {
                                              
                                           }

                                       }
                                     );
            bwHelper.AddBackgroundTask(
                                      (object s, DoWorkEventArgs a) =>
                                      {

                                          a.Result = CricketMatch.LoadbowlingSummary(AppSettings.ShowID, TeamType.TeamBBowling);
                                      },
                                      (object s, RunWorkerCompletedEventArgs a) =>
                                      {

                                          objbowlingsummary = (List<MatchBowlingScore>)a.Result;
                                          if (objbowlingsummary.Count > 0)
                                          {
                                              lbxteamsummaryBbowling.ItemsSource = objbowlingsummary;
                                           

                                          }
                                          else
                                          {
                                              
                                          }

                                      }
                                    );

            bwHelper.AddBackgroundTask(
                                      (object s, DoWorkEventArgs a) =>
                                      {

                                          a.Result = CricketMatch.GetExtraSection(AppSettings.ShowID);
                                      },
                                      (object s, RunWorkerCompletedEventArgs a) =>
                                      {
                                            objextras = (MatchExtras)a.Result;
                                            if (objextras!=null)
                                            {
                                                tblkAinningssumary.Text = objextras.TeamAInnings;
                                                tblkBsummaryinnings.Text = objextras.TeamBInnings;
                                                tblkATotsumary.Text = objextras.TeamATotal;
                                                txtTeamAtotal.Visibility = Visibility.Visible;
                                                tblkBTotsumary.Text = objextras.TeamBTotal;
                                                txtTeamBtotal.Visibility = Visibility.Visible;
                                                btnMatchResult.Visibility = Visibility.Visible;
                                                tblkMatchResult.Text = objextras.TeamResult;
                                            }
                                            else
                                            {
                                               
                                            }
                                      }
                                    );
          
          
          
          
            bwHelper.RunBackgroundWorkers();
            MyProgressBar1.IsIndeterminate = false;
        }
       
        private void btnMatchResult_Click(object sender, RoutedEventArgs e)
        {
            PageHelper.NavigateToDetailPage(AppResources.ScoreBoardPageName, AppSettings.ShowID);
        


        }
    }
}
